<template>
  <el-card shadow="never" class="mb10">
    <el-row>
      <el-form :inline="true" :model="queryData">
        <el-form-item label="品种编码">
          <el-input placeholder="请输入品种编码" v-model="queryData.keyWord" />
        </el-form-item>
        <el-form-item label="品种名称">
          <el-input placeholder="请输入品种名称" v-model="queryData.keyWord" />
        </el-form-item>
        <el-form-item label="状态">
          <el-select
            class="ml20"
            v-model="queryData.keyWord"
            placeholder="请选择状态"
          >
            <el-option label="正常" value="1"> </el-option>
            <el-option label="停用" value="2"> </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="flex-right">
        <el-button type="primary" :icon="RefreshLeft">重置</el-button>
        <el-button type="primary" :icon="Search" @click="initData" class="ml20">
          搜索
        </el-button>
      </div>
    </el-row>
  </el-card>
  <el-card shadow="never">
    <div class="mb10">
      <el-button type="primary" @click="onDialogNew()">+新增</el-button>
    </div>
    <el-table
      border
      stripe
      row-key="path"
      default-expand-all
      :data="tableData"
      
    >
      <el-table-column type="selection" width="55" />
      <el-table-column
        v-for="item in options"
        :key="item.type"
        :prop="item.props"
        :label="item.label"
        :width="item.width"
        :align="item.align"
        show-overflow-tooltip
        :fixed="item.fixed"
      >
        <template v-slot:default="scope" v-if="item.props === 'actions'">
          <el-button
            type="primary"
            size="small"
            text
            @click="onDialogNew(scope)"
          >
            编辑
          </el-button>
          <el-button type="danger" size="small" text @click="onDisable">
            {{ scope.row.lock ? "启用" : "停用" }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      class="mt-4"
      :total="total"
      :page-size="queryData.size"
      :page-sizes="[10, 20, 50, 100]"
      layout="total, sizes, prev, pager, next"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
  </el-card>

  <DialogVariety ref="dialogVarietyRef"></DialogVariety>
</template>

<script setup>
import { onMounted, ref } from "vue";
import { Search, RefreshLeft } from "@element-plus/icons-vue";
import { ElMessage, ElMessageBox } from "element-plus";
// import { getUserList } from "../../../api/index.js";
import { options } from "./options.js";
import DialogVariety from "./components/dialogVariety.vue";
import { sortRoute } from "../../../router/index.js";

const queryData = ref({
  keyWord: "",
  page: 1,
  size: 20,
});
const dialogVarietyRef = ref();

const tableData = ref([]);
const auditList = ref([]);
const total = ref(0);

const initData = () => {
  // getUserList(queryData.value).then((res) => {
  //   total.value = res.data.data.total;
  //   tableData.value = res.data.data.userList;
  // });
  tableData.value = sortRoute;
};

const handleCurrentChange = (val) => {
  queryData.value.page = val;
  initData(queryData.value);
};
const handleSizeChange = (val) => {
  queryData.value.page = val;
  initData(queryData.value);
};

const onDialogNew = (row = null) => {
  dialogVarietyRef.value.openDialog(row);
};

const onDelete = () => {
  console.log("onDelete!");
  ElMessageBox.confirm(
    "确认是否<span style='color:red;'>批量删除</span>",
    "复核提示",
    {
      type: "warning",
      dangerouslyUseHTMLString: true,
      confirmButtonText: "确定",
      cancelButtonText: "取消",
    }
  )
    .then(() => {
      ElMessage({
        type: "success",
        message: "Delete completed",
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "Delete canceled",
      });
    });
};
const onDisable = (row) => {
  ElMessageBox.confirm(
    `确认是否<span style='color:red;'>${
      row.lock ? "停用" : "启用"
    }xxxxxx</span>`,
    "报废提示",
    {
      type: "warning",
      dangerouslyUseHTMLString: true,
      confirmButtonText: "确定",
      cancelButtonText: "取消",
    }
  )
    .then(({ value }) => {
      ElMessage({
        type: "success",
        message: `Your email is:${value}`,
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "Input canceled",
      });
    });
};

onMounted(() => {
  initData();
});
</script>

<style lang="scss" scoped>
.henader-card {
  margin-bottom: 20px;
}
.mt-4 {
  float: right;
  text-align: right;
  margin-top: 20px;
  margin-bottom: 20px;
}
.el-button--text {
  margin-right: 15px;
}
.el-select {
  width: 300px;
}
.el-input {
  width: 300px;
}
.dialog-footer button:first-child {
  margin-right: 10px;
}
</style>
